{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "my = pd.read_csv('maoyanfilms_clean.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "大陆： 11528 香港： 2041 台湾： 2223\n"
     ]
    }
   ],
   "source": [
    "def films_area(x):\n",
    "    c_dl = 0\n",
    "    c_xg = 0\n",
    "    c_tw = 0\n",
    "    other = 0\n",
    "    list_a = x.split(',')\n",
    "    for one in list_a:\n",
    "        if one == \"中国大陆\":\n",
    "            c_dl += 1\n",
    "        elif one == \"中国香港\":\n",
    "            c_xg +=1\n",
    "        elif one == \"中国台湾\":\n",
    "            c_tw +=1\n",
    "        else:\n",
    "            other +=1\n",
    "    return pd.Series([c_dl,c_xg,c_tw])\n",
    "area_data = my['films_area'].apply(films_area)\n",
    "dalu = area_data[0].sum()\n",
    "xianggang = area_data[1].sum()\n",
    "taiwan = area_data[2].sum()\n",
    "print(\"大陆：\",dalu,\"香港：\",xianggang,\"台湾：\",taiwan)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\80423\\\\Desktop\\\\dataAnalysis\\\\中国三地区电影总发行数饼图.html'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pyecharts.options as opts\n",
    "from pyecharts.charts import Pie\n",
    "x_data = [\"大陆\", \"香港\", \"台湾\"]\n",
    "y_data = [11528, 2041,2223 ]\n",
    "data_pair = [list(z) for z in zip(x_data, y_data)]\n",
    "data_pair.sort(key=lambda x: x[1])\n",
    "\n",
    "(\n",
    "    Pie(init_opts=opts.InitOpts(width=\"1600px\", height=\"800px\", bg_color=\"#E0FFFF\"))\n",
    "    .add(\n",
    "        series_name=\"详细数据\",\n",
    "        data_pair=data_pair,\n",
    "        rosetype=\"radius\",\n",
    "        radius=\"40%\",\n",
    "        center=[\"50%\", \"50%\"],\n",
    "        label_opts=opts.LabelOpts(is_show=False, position=\"center\"),\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(\n",
    "            title=\"地区出品数饼图\",\n",
    "            pos_left=\"center\",\n",
    "            pos_top=\"20\",\n",
    "            title_textstyle_opts=opts.TextStyleOpts(color=\"#2F4F4F\"),\n",
    "        ),\n",
    "        legend_opts=opts.LegendOpts(is_show=False),\n",
    "    )\n",
    "    .set_series_opts(\n",
    "        tooltip_opts=opts.TooltipOpts(\n",
    "            trigger=\"item\", formatter=\"{a} <br/>{b}: {c} ({d}%)\"\n",
    "        ),\n",
    "        label_opts=opts.LabelOpts(color=\"#2F4F4F\"),\n",
    "    )\n",
    "    .render(\"中国三地区电影总发行数饼图.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
